package utils;

import java.util.Arrays;
import java.util.Comparator;

public class ArraySortWithOriginalIndex {
    public static void main(String[] args) {
        int[] array = {5, 2, 8, 2, 6};

        Integer[] indexes = new Integer[array.length];
        for (int i = 0; i < array.length; i++) {
            indexes[i] = i;
        }

        // 使用自定义比较器对索引数组进行排序，排序依据是原始数组的值
        Arrays.sort(indexes, Comparator.comparingInt(i -> -array[i]));

        // 输出排序后的数组和原始下标
        for (int index : indexes) {
            System.out.println("值：" + array[index] + "，原始下标：" + index);
        }
    }
}